﻿<%
'''分页类
Class PagerClass
	'分页GET参数名,跳转目标页,每页记录,当前页数,总页数,总记录数,
	Public PageVar, TargetPage, PageSize, PageNow, PageTotal, Recordcount, ShowPageNowA, ALeftExt, ARightExt, NLeftExt, NRightExt
	
	Public ShowInput, InputId, InputName, ShowSelect, SelectId, SelectName, FormatUrlFun, JumpFunName
	
	Private ParaStr, AOtherTagInfoStr, NOtherTagInfoStr, HrefModel
	
	Private Sub Class_Initialize()
		PageVar = "p"
		TargetPage = "/"
		PageSize = 10
		PageTotal = 1
		ShowPageNowA = False
		ALeftExt = ""
		ARightExt = ""
		NLeftExt = ""
		NRightExt = ""
		ShowInput = True
		InputId = "pagenumi"
		InputName = "pagenumi"
		ShowSelect = False
		SelectId = "pagenums"
		SelectName = "pagenums"
		FormatUrlFun = ""
		JumpFunName = "Go"
		ParaStr = ""
		AOtherTagInfoStr = ""
		NOtherTagInfoStr = ""
		PageNow = Null
	End Sub
	
	Private Sub Class_Terminate()
	End Sub
	
	Public Sub AddLinkPara(Byval p_pname, Byval p_pval)
		ParaStr = ParaStr & "&" & p_pname & "=" & p_pval
	End Sub
	
	'''通用的设置接口
	Public Sub [Set](Byval p_p, Byval p_v)
	End Sub
	
	Public Function AddAOtherTaginfo(Byval p_tagstr)
		AOtherTagInfoStr = AOtherTagInfoStr & " " & p_tagstr
	End Function
	
	Public Function AddNOtherTaginfo(Byval p_tagstr)
		NOtherTagInfoStr = NOtherTagInfoStr & " " & p_tagstr
	End Function
	
	Public Function FormatRsByPage(Byval p_rsObj)
		If IsNumeric(PageNow)=False Then
			If Request(PageVar)="" Then
				PageNow = 1
			ElseIf Not(IsNumeric(Request(PageVar))) Then
				PageNow = 1
			ElseIf CLng(Trim(Request(PageVar)))<1 Then
				PageNow = 1
			Else
				PageNow = CLng(Trim(Request(PageVar)))
			End If
		Else
			If PageNow<=0 Then
				PageNow = 1
			End If
			PageNow = CLng(PageNow)
		End If
		If TypeName(p_rsObj) = "Recordset" Then
			p_rsObj.PageSize = PageSize
			PageTotal = p_rsObj.PageCount
			Recordcount = p_rsObj.Recordcount
			If PageNow > PageTotal Then
				PageNow = PageTotal
			End If
			If Not p_rsObj.Eof Then
				p_rsObj.AbsolutePage = PageNow
			End If
		Else
			Exit Function
		End If
	End Function
	
	Private Sub InitPager()
		HrefModel = TargetPage & "?" & PageVar & "={1}" & ParaStr
		'直接对HrefModel进行FormatUrlFun
		If FormatUrlFun <> "" Then
			HrefModel = Eval(Replace(FormatUrlFun , "{0}", """" & HrefModel & """"))
		End If
	End Sub
	
	Private Function HrefForPage(Byval p_page)
		HrefForPage = Replace(HrefModel, "{1}", p_page)
		'每个进行FormatUrlFun
		'If FormatUrlFun <> "" Then
		'	HrefForPage = Eval(Replace(FormatUrlFun , "{0}", """" & HrefForPage & """"))
		'End If
	End Function
	
	Private Function NOutPut(Byval p_sstr, Byval p_enfa)
		Dim insideStr
		insideStr = ""
		If ShowPageNowA Or p_enfa Then
			insideStr = "<a href='" & HrefForPage(PageNow) & "'" & NOtherTagInfoStr & ">" & p_sstr & "</a>"
		Else
			insideStr = p_sstr & "&nbsp;"
		End If
		NOutPut = NLeftExt & insideStr & NRightExt & vbcrlf
	End Function
	
	Private Function NOutPutDef()
		NOutPutDef = NOutPut(PageNow, False)
	End Function
	
	Private Function AOutPut(Byval p_pagei, Byval p_sstr)
		AOutPut = ALeftExt & "<a href='" & HrefForPage(p_pagei) & "'" & AOtherTagInfoStr & ">" & p_sstr & "</a>" & ARightExt & vbcrlf
	End Function
	
	Private Function AOutPutDef(Byval p_pagei)
		AOutPutDef = AOutPut(p_pagei, p_pagei)
	End Function
	
	Private Function ZOutPut(Byval p_pagei, Byval p_sstr, Byval p_enfa, Byval p_enft)
		If (p_pagei = PageNow And p_enft = False) Then
			ZOutPut = NOutPut(p_sstr, p_enfa)
		Else
			ZOutPut = AOutPut(p_pagei, p_sstr)
		End If
	End Function
	
	Public Function OutPutDef()
		Call InitPager()
		Dim OutPutStr, i
		OutPutStr = ""
		OutPutStr = OutPutStr & ZOutPut(1, "首页", True, True)
		If PageNow - 1 <= 0 Then
			OutPutStr = OutPutStr & ZOutPut(1, "上一页", False, True)
		Else
			OutPutStr = OutPutStr & ZOutPut(PageNow-1, "上一页", False, True)
		End If
		If PageTotal <= 10 Then
			For i=1 To PageTotal
				OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
			Next
		ElseIf PageNow <= 6 then
			For i=1 To 6
				OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
			Next
			OutPutStr = OutPutStr & "..." & vbcrlf
			OutPutStr = OutPutStr & ZOutPut(PageTotal, PageTotal, False, False)
		Else
			For i=PageNow-3 To PageNow+3
				If i <= PageTotal Then
					OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
				End If
			Next
			OutPutStr = OutPutStr & "..." & vbcrlf
			OutPutStr = OutPutStr & ZOutPut(PageTotal, PageTotal, False, False)
		End If
		If PageNow + 1 >= PageTotal Then
			OutPutStr = OutPutStr & ZOutPut(PageTotal, "下一页", False, True)
		Else
			OutPutStr = OutPutStr & ZOutPut(PageNow+1, "下一页", False, True)
		End If
		OutPutStr = OutPutStr & ZOutPut(PageTotal, "尾页", True, True)
		OutPutStr = OutPutStr & " 跳转到&nbsp;" & vbcrlf
		OutPutStr = OutPutStr & "<script type='text/javascript'>" & vbcrlf
		OutPutStr = OutPutStr & "function " & JumpFunName & "(){" & vbcrlf
		OutPutStr = OutPutStr & "	var url='" & HrefModel & "';" & vbcrlf
		OutPutStr = OutPutStr & "	location=url.replace('{1}',document.getElementById('" & InputId & "').value);" & vbcrlf
		OutPutStr = OutPutStr & "	return false;" & vbcrlf
		OutPutStr = OutPutStr & "}" & vbcrlf
		OutPutStr = OutPutStr & "</script>" & vbcrlf
		OutPutStr = OutPutStr & "<input type='text' value='" & PageNow & "' style='width:22px;' id='" & InputId & "' name='" & InputName & "'" &_
		 						" onkeydown=""javascript: if(event.keyCode==13){ var url='" & HrefModel & "'; location=url.replace('{1}',this.value);return false;}"" />&nbsp;页" & vbcrlf
		OutPutStr = OutPutStr & "<a href='javascript:" & JumpFunName & "();'>GO</a>"
		OutPutDef = OutPutStr
	End Function
	
	Public Function OutPut()
		Call InitPager()
		Dim OutPutStr, i
		OutPutStr = ""
		If PageTotal <= 10 Then
			For i=1 To PageTotal
				OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
			Next
		ElseIf PageNow <= 6 then
			For i=1 To 6
				OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
			Next
			OutPutStr = OutPutStr & "..." & vbcrlf
			OutPutStr = OutPutStr & ZOutPut(PageTotal, PageTotal, False, False)
		Else
			For i=PageNow-3 To PageNow+3
				If i <= PageTotal Then
					OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
				End If
			Next
			OutPutStr = OutPutStr & "..." & vbcrlf
			OutPutStr = OutPutStr & ZOutPut(PageTotal, PageTotal, False, False)
		End If
		OutPut = OutPutStr
	End Function
	
	Public Function OutPutForMaxLaw()
		Call InitPager()
		Dim OutPutStr, i
		OutPutStr = ""
		OutPutStr = OutPutStr & ZOutPut(1, "&lt;", True, True)
		If PageTotal <= 10 Then
			For i=1 To PageTotal
				OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
			Next
		ElseIf PageNow <= 6 then
			For i=1 To 6
				OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
			Next
			OutPutStr = OutPutStr & "..." & vbcrlf
			OutPutStr = OutPutStr & ZOutPut(PageTotal, PageTotal, False, False)
		Else
			For i=PageNow-3 To PageNow+3
				If i <= PageTotal Then
					OutPutStr = OutPutStr & ZOutPut(i, i, False, False)
				End If
			Next
			OutPutStr = OutPutStr & "..." & vbcrlf
			OutPutStr = OutPutStr & ZOutPut(PageTotal, PageTotal, False, False)
		End If
		OutPutStr = OutPutStr & ZOutPut(PageTotal, "&gt;", True, True)
		OutPutForMaxLaw = OutPutStr
	End Function
	
End Class
%>